package com.example.www.Controller;

import com.example.www.Base.Result;
import com.example.www.Entity.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;

@RestController
public class ConnectController
{
    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.username}")
    private String username;
    @Value("${spring.mail.to}")
    private String to;
    @PostMapping("/api/newproject")
    @CrossOrigin
    public Result newProject(@RequestBody Project project){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(username);
        message.setTo(to);
        String subject="新项目：来自"+project.getName();
        message.setSubject(subject);
        String context=project.toString();
        message.setText(context);
        javaMailSender.send(message);
        return Result.OK();
    }

}
